package org.i1510.common.utils.file;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.i1510.common.bean.FileBean;
import org.junit.Test;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;

public class FileManager { 
 
	

 
    /**
    *@Author Rambo
    *@Desc：可使用通配符读取路径文件存到List<FileBean>
    *@param location
    *@return
    *@throws IOException TODO
    *@Version  XMLManager.java,v 1.1 2013-10-8 下午6:26:24 
    */
    public List<FileBean> readFile(String location) throws IOException { 
        ResourcePatternResolver resourceLoader = new PathMatchingResourcePatternResolver(); 
        Resource[] source = resourceLoader.getResources(location); 
        List<FileBean> fileList = new ArrayList<FileBean>();
        for (int i = 0; i < source.length; i++) { 
            Resource resource = source[i]; 
            FileBean fileBean  = new FileBean();
            fileBean.setFile(resource.getFile());
            fileBean.setFileName(resource.getFilename());
            fileBean.setFilePath(resource.getFile().getPath());
            System.out.println(resource.getFile().getPath()); 
            fileList.add(fileBean);
        } 
        return fileList;
    } 
 
    @Test
    public  void mainTest() { 
    	String location = "classpath:/config/**/spring-quartz.xml"; 
    	FileManager fm = new FileManager(); 
        try { 
        	List<FileBean> fileList = new ArrayList<FileBean>();
        	fileList = fm.readFile(location); 
        } catch (IOException e) { 
            e.printStackTrace(); 
        } 
    } 
} 